package com.zxbg.controller.systemtoolsController;

import com.zxbg.controller.Code;
import com.zxbg.controller.Result;
import com.zxbg.domain.ErrorPage;
import com.zxbg.service.systemtoolsService.BusinessManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/BusinessManagement")
public class BusinessManagementController {
    @Autowired
    BusinessManagementService businessManagementService;

    @GetMapping("/{error_type}")
    public Result getErrorPageInfo(@PathVariable String error_type, @RequestHeader Integer tenant_id) {
        return new Result(Code.GET_OK, businessManagementService.getErrorPageInfo(error_type, tenant_id));
    }

    @PostMapping
    public Result addErrorPage(@RequestBody ErrorPage errorPage, @RequestHeader Integer tenant_id, @RequestHeader String employee_id){
        String res = businessManagementService.addErrorPage(errorPage, tenant_id, employee_id);
        return new Result(res.equals("") ? Code.SAVE_OK : Code.SAVE_ERR, res, res);
    }

    @PutMapping
    public Result updateErrorPage(@RequestBody ErrorPage errorPage, @RequestHeader String employee_id) {
        String res = businessManagementService.updateErrorPage(errorPage, employee_id);
        return new Result(res.equals("") ? Code.UPDATE_OK : Code.UPDATE_ERR, res, res);
    }

    @DeleteMapping("/{error_type}")
    public Result deleteErrorPage(@PathVariable String error_type, @RequestHeader Integer tenant_id) {
        return new Result(Code.DELETE_OK, businessManagementService.deleteErrorPage(error_type, tenant_id));
    }
}
